package com.ruoyi.safe.controller.web;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.safe.domain.ListMaintenance;
import com.ruoyi.safe.service.IListMaintenanceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 养护清单Controller
 * 
 * @author buxi
 * @date 2023-11-06
 */
@RestController
@RequestMapping("/list/maintenance")
public class ListMaintenanceController extends BaseController
{
    @Autowired
    private IListMaintenanceService listMaintenanceService;

    /**
     * 查询养护清单列表
     */
    @PreAuthorize("@ss.hasPermi('list:maintenance:list')")
    @GetMapping("/list")
    public TableDataInfo list(ListMaintenance listMaintenance)
    {
        startPage();
        List<ListMaintenance> list = listMaintenanceService.selectListMaintenanceList(listMaintenance);
        return getDataTable(list);
    }

    /**
     * 导出养护清单列表
     */
    @PreAuthorize("@ss.hasPermi('list:maintenance:export')")
    @Log(title = "养护清单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ListMaintenance listMaintenance)
    {
        List<ListMaintenance> list = listMaintenanceService.selectListMaintenanceList(listMaintenance);
        ExcelUtil<ListMaintenance> util = new ExcelUtil<ListMaintenance>(ListMaintenance.class);
        util.exportExcel(response, list, "养护清单数据");
    }

    /**
     * 获取养护清单详细信息
     */
    @PreAuthorize("@ss.hasPermi('list:maintenance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(listMaintenanceService.selectListMaintenanceById(id));
    }

    /**
     * 新增养护清单
     */
    @PreAuthorize("@ss.hasPermi('list:maintenance:add')")
    @Log(title = "养护清单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ListMaintenance listMaintenance)
    {
        return toAjax(listMaintenanceService.insertListMaintenance(listMaintenance));
    }

    /**
     * 修改养护清单
     */
    @PreAuthorize("@ss.hasPermi('list:maintenance:edit')")
    @Log(title = "养护清单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ListMaintenance listMaintenance)
    {
        return toAjax(listMaintenanceService.updateListMaintenance(listMaintenance));
    }

    /**
     * 删除养护清单
     */
    @PreAuthorize("@ss.hasPermi('list:maintenance:remove')")
    @Log(title = "养护清单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(listMaintenanceService.deleteListMaintenanceByIds(ids));
    }
}
